var $editDialog;
var $viewChartDialog;
var showPage;
var getEditDialog,checkLine;
require([ 'grid', 'topBar', 'highcharts', 'date', 'zTreeCheckbox','layout'], function () {
	var today =  new Date();
	$topBar = $(".topBar")
	$("#reportDate").val(today.dateAdd('d',-1).format('yyyy-MM-dd'));
	var exportPdfUrl="";//导出PDFURl
	var exportPdfParams={};//导出PDF参数
	var postData;
	var idStr;
	var corpId="";
	var showCorp = "";
	var showLineName = "";
	var num = 1;
	//加载企业
	var $corpTree;
	// 树的参数配置
	var corpSetting = {
		data: {
			key: {
				name: "corpName"
			},
			simpleData: {
				enable: true,
				idKey: "corpId",
				pIdKey: "parentCorpId",
				rootPId: 0
			}
		},
		view: {
			showIcon: true
		},
		callback: {
			onClick: sysCorpTreeClick
		}
	};
	$.ajaxExt({
		url : "/sysCorpInfo/getSysCorpInfoList.htm"
	}).done(function(data) {
		if (data) {
			//生成树
			$corpTree = $.fn.zTree.init($("#corpTreeUl"), corpSetting, data);
			$corpTree.expandAll(true)
		}
	});
	function sysCorpTreeClick(event, treeId, treeNode,clickFlag){
		corpId=treeNode.corpId;
		$("#showSelectLines").empty();	
		showCorp = '<a>'+treeNode.corpName+'</a>';
		$("#showSelectLines").html(showCorp);
		$('.all-show').html(showCorp);
		
	}

	//加载用户线路资源
//	$.ajaxExt({
//		url: "/homeCaptain/getCaptainLineInfo.htm"
//	}).done(function(data){
//		if(data){
//			console.info(data);
//			var html = "", tmpOrganId = "";
//			$.each(data, function(index, item){
//				if(tmpOrganId != item.organId){
//					tmpOrganId = item.organId;
//					if(html != '')
//						html += "</ul><h4>"+item.organName+"</h4><ul>";
//					else
//						html += "<h4>"+item.organName+"</h4><ul>";
//				}
//				html += "<li><input type='checkbox' value='"+item.lineId+"' name='lineChk' dscVal='"+item.lineName
//					+"' onClick='checkLine(\""+item.lineName+"\")'><span onClick='textClick(this)'>"+item.lineName+"</span></li>";
//			});
//			if(html && html != ''){
//				html += "</ul>";
//			}
//			$("#lineChkBox").html(html);
//		}
//	});
	
	//显示在路线选择下方
	checkLine = function (event, treeId, treeNode,clickFlag){
		showLineName='';
		var corpName = '';
        var nodes = $lineTree.getCheckedNodes(true);
        $.each(nodes, function (index, node) {
//        	console.info(node);
//        	if(node.level==1){
//        		corpName = node.name;
//        	}
        	if(node.type=='LINE'){
        		showLineName += '<a>'+node.corpShrtnm+'-'+node.name+'</a>';
        	}
        	
        });

//		corpId=treeNode.corpId;
//		console.info(corpId);
//		$("#showSelectLines").empty();	
//		showLineName = '';
//		$("input[name='name']:checked").each(function(){
//			showLineName += '<a>'+$(this).attr('dscVal')+'</a>'
//		});
		$("#showSelectLines").html(showLineName);
		$('.all-show').html(showLineName);
	};
	
	//加载线路
	var $lineTree;
	var lineSetting = {
			data: {
				key: {
					name: "name"
				},
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "parentId",
					rootPId: 0
				}
			},
			check: {
				enable: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "s", "N": "ps" }
			},
			view: {
				showIcon: true
			},
			callback: {
				onCheck: checkLine
			}
		};
	
	$.ajaxExt({
		url : "/qualityIndex/getLineInfoList.htm"
	}).done(function(data) {
		if (data) {
//			console.info(data);
			//生成树
			$lineTree = $.fn.zTree.init($("#lineChkBox"), lineSetting, data);
			$("#lineChkBox").find('>li:gt(0)').remove();
			$('>li>span:eq(0)', $("#lineChkBox")).trigger('click');
		}
	});
	
	function textClick(obj){
//		console.info($(this));
//		$(this).find('input').click();
//		console.info($(obj).find(':checkbox').click());
		$(obj).parent().find('input').click();
	};

	//加载车辆
	var $carTree;
	var carSetting = {
		data: {
			key: {
				name: "name"
			},
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "parentId",
				rootPId: 0
			}
		},
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType: { "Y": "s", "N": "ps" }
		}
	};
	$.ajaxExt({
		url : "/qualityIndex/getCarInfoList.htm"
	}).done(function(data) {
		if (data) {
//			console.info(data);
			//生成树
			$carTree = $.fn.zTree.init($("#carTreeUl"), carSetting, data);
			$("#carTreeUl").find('>li:gt(0)').remove();
			$('>li>span:eq(0)', $("#carTreeUl")).trigger('click');
		}
	});
	
	
	
	$("#selAll").click(function(){
		$("#lineChkBox").find(':checkBox').prop("checked", this.checked);
		if(this.checked){
			$("#showSelectLines").html('<a>全部线路</a>');
			$('.all-show').html('<a>全部线路</a>');
		}else{
			$("#showSelectLines").empty();
			$('.all-show').empty();
		}
	});
	
	$(function(){
        (function(){
            var _int;
            $('.line-display-area').hover(function(){
                var _t = this;
                _int && clearInterval(_int);
                _int = setTimeout(function(){
                    $('.all-show',_t).show();
                },500);
            },function(){
                var _t = this;
                _int && clearInterval(_int);
                _int = setTimeout(function(){
                    $('.all-show',_t).hide();
                },400);
            });
        }());
    });
	
	
    $top = $('#top');
    $('body').layout();
    $top.topBar({
    	left: [{
            type: 'filter-more',
            dateType: 'custom',
            search: function () {
                search();
            },
            item: [
				{
				    text: '时间快捷',
				    name1: 'beginTime',
				    name2: 'endTime',
				    type: 'dateLine'
				},
                 {
                    text: '故障汇总',
                    name: 'problemType',
                    type: 'item-select',
                    data: [
                        {text: '全部', value: '',selected:true},   
                        {text: '里程有问题', value: '1'},
                        {text: '能耗有问题', value: '2'},
                        {text: '在线率有问题', value: '3'},
                        {text: '行为有问题', value: '4'},
                        {text: '故障有问题', value: '5'},
                        {text: '报站有问题', value: '6'}
                    ]
                }
            ]
        }],
        right: [
            {
                text: '导出',
                type: 'export-btn',
                authority: '',
                item: [
                    {
                        text: 'Excel导出',
                        click: function () {
                            exportFile('Excel');
                        }
                    },
                    {
                        text: 'PDF导出',
                        click: function () {
                            exportFile('Pdf');
                        }
                    }
                ]
            },
            {
				text: '隐藏/显示饼图',
				type: 'btn',
				width: '80',
				click: function () {
					if(num % 2 != 0){
						$("#carProblem").hide();
					}else{
						$("#carProblem").show();
					}
					num++;
				}
			}
        ]
    });
    
    

	//获取所有选中车辆节点的值
	function getCheckedCarNodes() {
		var nodes = $carTree.getCheckedNodes(true);
		var checkedNodes = [];
		$.each(nodes, function (index, node) {
			if (node.type=='CAR') {
				checkedNodes.push(node.id);
			}
		});
        return checkedNodes;
	}

	//获取所选线路
	function getCheckedLineNodes(){
		var lineIds = [];
//		$("input[name='lineChk']:checked").each(function(){
//			lineIds.push($(this).val());
//		});
		var nodes = $lineTree.getCheckedNodes(true);
        $.each(nodes, function (index, node) {
//        	console.info(node);
        	if(node.type=='LINE'){
        		lineIds.push(node.id);
        	}
        });
        return lineIds;
	}
	

	$("#exportPDF").hide();
	$("#exportPDF").click(function(){
		exportSuffer("Pdf.htm");
	});
	
	$("#exportEXCEL").hide();
	$("#exportEXCEL").click(function(){
		exportSuffer("Excel.htm");
	});
	
	function exportSuffer(suffit){
		if(exportPdfUrl){
			exportPdfParams.corpId=corpId;
			exportPdfParams.reportDate=$("#reportDate").val();
			if($("#carTreeUl").is(":visible")){
				exportPdfParams.orgIds=getCheckedCarNodes();
			}
			if($("#lineChkBox").is(":visible")){
				exportPdfParams.orgIds=getCheckedLineNodes();
			}
			if(exportPdfUrl == '/carQuestionAnls/exportTBsStatProbAna'){
				exportPdfParams.beginTime = postData.beginTime;
				exportPdfParams.endTime = postData.endTime;
			}else{
				exportPdfParams.dayOnDay=$("#dayOnDay").val();
				exportPdfParams.dayOnWeak=$("#dayOnWeak").val();
				exportPdfParams.reportDate = $("#reportDate").val();
			}
			$.exportFile(exportPdfUrl+suffit,exportPdfParams);
		}
		else{
			$.messager.alert("提示","请选择先查询数据");
		}
	}

	$("#qualityIndex, #qualityAnlsSummary, #qualityAnlsDetail, #carQuestionAnls").click(function(){
		//改变按钮样式
        $(".item6, .item7, .item8, .item9").removeClass("active");
		$(this).parent().addClass("active");
		//切换功能区域显示
		$("#qualityIndexDiv, #qualityAnlsSummaryDiv, #qualityAnlsDetailDiv, #carQuestionAnlsDiv").hide();
		var idStr = $(this).attr("id");
		$("#"+idStr+"Div").show();
		$("#exportPDF").show();
		$("#exportEXCEL").show();
		switch(idStr){
			case "qualityIndex":
                // $("#showSelectLines").html(showCorp);
                // $('.all-show').html(showCorp);
                // $("#showSelectLines").show();
                // $("#carTreeUl").hide();
                // $("#corpTreeUl").show();
                // $("#lineChkBox").hide();
                // $("#exportPDF").hide();
                // $("#exportEXCEL").hide();
                // $(".time-select-area").show();
                // $(".filter-wrap").show();
                // loadIndexPage();
                // $("#orgSelect").html("车辆选择");
                $("#showSelectLines").hide();
                $('.all-show').hide();
                $("#carTreeUl").show();
                $("#lineChkBox").hide();
                $("#corpTreeUl").hide();
                $(".time-select-area").show();
                $(".filter-wrap").show();
                $("#orgSelect").html("车辆选择");
				break;
			case "qualityAnlsSummary":
				$("#showSelectLines").html(showLineName);
				$('.all-show').html(showLineName);
				$("#showSelectLines").show();
				$("#carTreeUl").hide();
				$("#corpTreeUl").hide();
				$("#lineChkBox").show();
				$(".time-select-area").show();
				$(".filter-wrap").show();
				$("#orgSelect").html("线路选择");
				break;
			case "qualityAnlsDetail":
				$("#showSelectLines").hide();
				$('.all-show').hide();
				$("#carTreeUl").show();
				$("#lineChkBox").hide();
				$("#corpTreeUl").hide();
				$(".time-select-area").show();
				$(".filter-wrap").show();
				$("#orgSelect").html("车辆选择");
				break;
			case "carQuestionAnls":
				$("#showSelectLines").hide();
				$('.all-show').hide();
				$("#carTreeUl").show();
				$("#lineChkBox").hide();
				$("#corpTreeUl").hide();
				$("#orgSelect").html("车辆选择");
				$(".time-select-area").hide();
				$(".filter-wrap").hide();
//				loadarQuestionAnlsGrid();
//				search();
				break;
		}

		showPage();
	});

    function toggleSelectArea(left){
        $(".line-select-container").stop().animate({
            "left": left
        },400);
        $(".line-select-area")[left>0?'removeClass':'addClass']("line-select-default");
    }


	$(".line-select-area").click(function(){
		if($(this).hasClass("line-select-default")) {
            toggleSelectArea(158);
		} else {
            toggleSelectArea(-127);
		}
	});

	$(".confirm-btn").click(function(){
        toggleSelectArea(-127);
        showPage();
	});

    $(document).on('click',function(e){
        if($(".line-select-area").hasClass('line-select-default')){
            return;
        }
        var e = e.target|| e.srcElement;
        if($(e).closest('.line-select-container').length == 0 && $(e).closest('.line-select-area').length == 0){
            toggleSelectArea(-127);
        }
    });

	//设置高度
	function setHeight() {
		var height = $(window).height();
		$("#layoutLeft,#layoutLeft > .layout-right").height(height);
		$("#corpTree").height(height-53);
	}

	window.onresize = setHeight;

	//设置高度
	setHeight();

	//显示页面数据
	showPage = function(){
		var elId="";
		$(".item6, .item7, .item8, .item9").each(function(){
			if($(this).hasClass('active')){
				elId = $(this).find('a').attr('id');
			}
		});
		switch(elId){
			case "qualityIndex":
				loadIndexPage();
				break;
			case "qualityAnlsSummary":
				$("#tBsStatWeakBhvPage, #tBsStatWeakMftPage, #tBsStatWeakOnlinePage, #tBsStatWeakMilePage,#tBsStatWeakEnerConsPage,#tBsStatWeakStopPage").each(function(){
					if($(this).hasClass('active')){
						var page = $(this).attr('id');
						getQualityAnlsSummaryTab(("#"+page.replace("Page","Grid")));
						exportPdfUrl="";
						exportPdfUrl='/qualityAnlsSummary/exportT'+page.substring(1).replace("Page","");
					}
				});
				break;
			case "qualityAnlsDetail":
				$("#tBsStatDayBhvPage, #tBsStatDayMftPage, #tBsStatDayOnlinePage, #tBsStatDayMilePage, #tBsStatDayEnerConsPage, #tBsStatDayStopPage").each(function(){
					if($(this).hasClass('active')){
						var page = $(this).attr('id');
						getQualityAnlsDetailPage(("#"+page.replace("Page","Grid")));
						exportPdfUrl="";
						exportPdfUrl='/qualityAnlsDetail/exportT'+page.substring(1).replace("Page","");
					}
				});
				break;
			case "carQuestionAnls":
				exportPdfUrl="/carQuestionAnls/exportTBsStatProbAna";
//				loadarQuestionAnlsGrid();
//				search();
				break;
		}
	}

	//质量指标页面
    $('#carDataQualityIndexGrid').grid({
    	url : "/qualityIndex/searchQualityIndexPage.htm",
    	// height:gridHeight1,
    	// // width: $(window).width() - 214,
    	// autowidth:true,
    	// shrinkToFit:true,
    	// multiselect: false,
        multiselect:false,
        height: $(window).height(),
        width: gridWidth1,
    	colModel:[
    		{name: "indexLevel1Name", label:"一级指标"},
    		{name: "indexLevel2Name", label:"二级指标"},
    		{name: "indexLevel3Name", label:"三级指标"},
            {name: "indexDesc", label:"四级指标"},
            {name: "indexType", label:"指标ID"},
            {name: "indexValue1", label:"指标值"},
            {name: "indexValue2", label:"指标参考1"},
            {name: "indexValue3", label:"指标参考2"},
    		]
    });
	//分页查询日常检测指标
	// $('#dailyIndexGrid').grid({
	// 	url : "/qualityIndex/searchQualityIndexPage.htm",
	// 	height:200,
	// 	width: $(window).width() - 214,
	// 	//autowidth:true,
	// 	shrinkToFit:true,
	// 	multiselect: false,
	// 	colModel:[
	// 		{name: "targetName", label:"指标名称"},
	// 		{name: "targetValue", label:"指标值"},
	// 		{name: "reportDate", label:"扫描日期"},
	// 		{name: "errorLevel", label:"异常度",align: "center",
	// 			formatter: function (cellvalue, options, rowObject) {
	// 				if(cellvalue==1){
	// 					return '<span class="abnormal-degree">Ⅰ</span>';
	// 				}else if(cellvalue==2){
	// 					return '<span class="abnormal-degree second">Ⅱ</span>';
	// 				}else if(cellvalue==3){
	// 					return '<span class="abnormal-degree third">Ⅲ</span>';
	// 				}
	// 			}
	// 		}]
	// });
	//分页查询TY文件指标
	// $('#tyFilesIndexGrid').grid({
	// 	url : "/qualityIndex/searchQualityIndexPage.htm",
	// 	height:200,
	// 	width:$(window).width() - 214,
	// 	//autowidth:true,
	// 	shrinkToFit:true,
	// 	multiselect: false,
	// 	colModel:[
	// 		{name: "remarks", label:"remarks",hidden: true},
	// 		{name: "targetName", label:"指标名称"},
	// 		{name: "targetValue", label:"指标值",align: "right"},
	// 		{name: "referenceValue", label:"参考值",align: "right"},
	// 		{name: "reportDate", label:"扫描日期",align: "center"},
	// 		{name: "errorLevel", label:"严重度",align: "center",
	// 			formatter: function (cellvalue, options, rowObject) {
	// 				if(cellvalue==1){
	// 					return '<span class="abnormal-degree">Ⅰ</span>';
	// 				}else if(cellvalue==2){
	// 					return '<span class="abnormal-degree second">Ⅱ</span>';
	// 				}else if(cellvalue==3){
	// 					return '<span class="abnormal-degree third">Ⅲ</span>';
	// 				}
	// 				else {
	// 					return '';
	// 				}
	// 			}
	// 		},
	// 		{name: "todo", label: "详细清单", formatter: 'operArea', align: "center",
	// 			formatoptions: [
	// 				{
	// 					text: '详细',
	// 					css:'operate-scan',
	// 					click: function (data) {
	// 						var errorLevel="";
	// 						if(data.errorLevel){
	// 							errorLevel=data.errorLevel.substr(data.errorLevel.indexOf('>')+1,data.errorLevel.indexOf('</')-data.errorLevel.indexOf('>')-1);
	// 							data.errorLevel=errorLevel;
	// 						}
	// 						getEditDialog(data);
	// 					}
	// 				}]
	// 		}]
	// });

	//  getEditDialog=function(data) {
	// 	if (!$editDialog) {
	// 		$editDialog = $('<div>').dialog({
	// 			url: './report/dataQualityIndex/qualityIndexDetails.htm',
	// 			title:'详细清单',
	// 			height: 480,
	// 			width: 720,
	// 			buttons: [
	// 				{
	// 					text: '关闭',
	// 					css: 'btn-cancel',
	// 					click: function () {
	// 						$(this).dialog('close');
	// 					}
	// 				}
	// 			]
	// 		});
	// 	}
	// 	$editDialog.dialog('exec', 'loadData',data);
	// 	$editDialog.dialog('open');
	// }
    //
	// function loadIndex(list,el){
	// 	var html="";
	// 	for(var i=0;i<2;i++){
	// 		html+="<ul class='clearfix'>";
	// 		for(var j=0;j<5;j++){
	// 			var index = i*5+j;
	// 			if(list[index]){
	// 				html+="<li onclick=getEditDialog(";
	// 				html+="{";
	// 				html+="'targetName':'"+(list[index].targetName?list[index].targetName:"")+"'";
	// 				html+=",'targetValue':'"+(list[index].targetValue?list[index].targetValue:"")+"'";
	// 				if(list[index].referenceValue){
	// 					html+=",'referenceValue':'"+list[index].referenceValue+"'";
	// 				}
	// 				if(list[index].reportDate){
	// 					html+=",'reportDate':'"+list[index].reportDate+"'";
	// 				}if(list[index].remarks){
	// 					html+=",'remarks':'"+list[index].remarks+"'";
	// 				}
	// 				if(list[index].errorLevel){
	// 					html+=",'errorLevel':'"+list[index].errorLevel+"'";
	// 					html+="})>";
	// 					if(list[index].errorLevel=='1'){
	// 						html+="<h4 class='c-green'>"+(list[index].targetName?list[index].targetName:"")+"</h4>";
	// 						html+="<p class='c-green'>"+(list[index].targetValue?list[index].targetValue:"")+"</p>";
	// 					}else if(list[index].errorLevel=='2'){
	// 						html+="<h4 class='c-yellow'>"+(list[index].targetName?list[index].targetName:"")+"</h4>";
	// 						html+="<p class='c-yellow'>"+(list[index].targetValue?list[index].targetValue:"")+"</p>";
	// 					}else if(list[index].errorLevel=='3'){
	// 						html+="<h4 class='c-red'>"+(list[index].targetName?list[index].targetName:"")+"</h4>";
	// 						html+="<p class='c-red'>"+(list[index].targetValue?list[index].targetValue:"")+"</p>";
	// 					}
	// 				}
	// 				else{
	// 					html+="})>";
	// 					html+="<h4>"+list[index].targetName+"</h4>";
	// 					html+="<p>"+list[index].targetValue+"</p>";
	// 				}
	// 				html+="</li>";
	// 			}
	// 			else{
	// 				html+="<li>";
	// 				html+="<h4></h4>";
	// 				html+="<p></p>";
	// 				html+="</li>";
	// 			}
	// 		}
	// 		html+="</ul>";
	// 	}
	// 	$(el).html(html);
	// }
	// loadIndex([],"#dailyIndexDiv");
	// loadIndex([],"#tyFilesIndexDiv");
	// function loadIndexPage(){
	// 	loadIndex([],"#dailyIndexDiv");
	// 	loadIndex([],"#tyFilesIndexDiv");
	// 	loadDailyIndex();
	// 	loadDailyIndexGrid();
	// 	loadTyFilesIndex();
	// 	loadTyFilesIndexGrid();
	// }
	//日常检测指标
	// function loadDailyIndex() {
	// 	if(corpId&&$("#reportDate").val()) {
	// 		$.ajaxExt({
	// 			url: "/qualityIndex/searchQualityIndexList.htm",
	// 			data: {"corpId":corpId,"reportDate":$("#reportDate").val(),"targetLevel1":"日常指标","targetLevel2":"1级"}
	// 		}).done(function (data) {
	// 			if(data){
	// 				loadIndex(data,"#dailyIndexDiv");
	// 			}
	// 		});
	// 	}
	// }
	//日常检测指标Grid
	// function loadDailyIndexGrid(){
	// 	if(corpId&&$("#reportDate").val()) {
	// 		$("#dailyIndexGrid").grid('setGridParam', {
	// 			datatype: "JSON",
	// 			page: 1,
	// 			postData: {"corpId":corpId,"reportDate":$("#reportDate").val(),"targetLevel1":"日常指标","targetLevel2":"2级"}
	// 		}).trigger("reloadGrid");
	// 	}
	// }
	//TY文件指标
	// function loadTyFilesIndex() {
	// 	if(corpId&&$("#reportDate").val()) {
	// 		$.ajaxExt({
	// 			url: "/qualityIndex/searchQualityIndexList.htm",
	// 			data: {"corpId":corpId,"reportDate":$("#reportDate").val(),"targetLevel1":"TY指标","targetLevel2":"1级"}
	// 		}).done(function (data) {
	// 			if(data){
	// 				loadIndex(data,"#tyFilesIndexDiv");
	// 			}
	// 		});
	// 	}
	// }
	//TY文件指标Grid
	// function loadTyFilesIndexGrid(){
	// 	if(corpId&&$("#reportDate").val()) {
	// 		$("#tyFilesIndexGrid").grid('setGridParam', {
	// 			datatype: "JSON",
	// 			page: 1,
	// 			postData: {"corpId":corpId,"reportDate":$("#reportDate").val(),"targetLevel1":"TY指标","targetLevel2":"2级"}
	// 		}).trigger("reloadGrid");
	// 	}
	// }

	//质量指标页面
	$("#carDataQualityIndexPage","#lineDataQualityIndexPage","#corpDataQualityIndexPage").click(function(){
		//改变按钮样式
        $("#carDataQualityIndexPage","#lineDataQualityIndexPage","#corpDataQualityIndexPage").removeClass("active");
        $(this).addClass("active");
        //切换功能区域显示
		$("#carDataQualityIndexDiv","#lineDataQualityIndexDiv","#corpDataQualityIndexDiv").hide();
		var page = $(this).attr("id");
		$("#"+page.replace("Page","Div")).show();
		//导出



	});

    //加载质量指标tab
    function getDataQualityTab(obj){
        var lineIds = getCheckedLineNodes();
        var carIds =
        if(lineIds.length>0&&$("#reportDate").val()) {
            $(obj).grid('setGridParam', {
                datatype: "JSON",
                page: 1,
                postData: {"orgIds":lineIds,"reportDate":$("#reportDate").val(),"dayOnDay":$("#dayOnDay").val(),"dayOnWeak":$("#dayOnWeak").val()}
            }).trigger("reloadGrid");
        }
    }
	//质量分析汇总页面
	$("#tBsStatWeakBhvPage, #tBsStatWeakMftPage, #tBsStatWeakOnlinePage, #tBsStatWeakMilePage,#tBsStatWeakEnerConsPage,#tBsStatWeakStopPage").click(function(){
		//改变按钮样式
		$("#tBsStatWeakBhvPage, #tBsStatWeakMftPage, #tBsStatWeakOnlinePage, #tBsStatWeakMilePage,#tBsStatWeakEnerConsPage,#tBsStatWeakStopPage").removeClass("active");
		$(this).addClass("active");
		//切换功能区域显示
		$("#tBsStatWeakBhvDiv, #tBsStatWeakMftDiv, #tBsStatWeakOnlineDiv, #tBsStatWeakMileDiv, #tBsStatWeakEnerConsDiv, #tBsStatWeakStopDiv").hide();
		var page = $(this).attr("id");
		$("#"+page.replace("Page","Div")).show();
		exportPdfUrl="";
		exportPdfUrl='/qualityAnlsSummary/exportT'+page.substring(1).replace("Page","");
		getQualityAnlsSummaryTab(("#"+page.replace("Page","Grid")));
	});
	//加载质量分析汇总tab
	function getQualityAnlsSummaryTab(obj){
		var lineIds = getCheckedLineNodes();
		if(lineIds.length>0&&$("#reportDate").val()) {
			$(obj).grid('setGridParam', {
				datatype: "JSON",
				page: 1,
				postData: {"orgIds":lineIds,"reportDate":$("#reportDate").val(),"dayOnDay":$("#dayOnDay").val(),"dayOnWeak":$("#dayOnWeak").val()}
			}).trigger("reloadGrid");
		}
	}
    //图表分析
	function getViewChartDialog(type,data){
		if (!$viewChartDialog) {
			$viewChartDialog = $('<div>').dialog({
				url: './report/dataQualityIndex/viewDataChart.htm',
				title:'图表分析',
				height: 600,
				width: 800,
				buttons: [
					{
						text: '关闭',
						css: 'btn-cancel',
						click: function () {
							$(this).dialog('close');
						}
					}
				]
			});
		}
		$viewChartDialog.dialog('exec', 'loadData',type,$("#reportDate").val(),$("#dayOnDay").val(),$("#dayOnWeak").val(),data);
		$viewChartDialog.dialog('open');
	}
	var gridWidth1 = $(window).width() - 198,
		gridHeight1 = $(window).height() - 105;
	//初始化统计表格
	//行为统计
	$('#tBsStatWeakBhvGrid').grid({
		url : "/qualityAnlsSummary/searchTBsStatWeakBhvPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpId", label:"corpId",hidden: true},
			{name: "organId", label:"organId",hidden: true},
			{name: "lineId", label:"lineId",hidden: true},
			{name: "bhvType",label:"bhvType",hidden: true},
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "bhvTypeName",label:"行为类型",formatter:"customCurrency", 
				formatoptions:{
	                redbtn:true,
	                css:'text-link',
	                clickFn:function(rowObject,cellvalue){
	                	var reportDate = rowObject.reportDate;
	                	var beginTime = reportDate.substring(0,10);
	                	var endTime = reportDate.substring(11,21);
	                	var bhvType = rowObject.bhvType;
	                	var lineId = rowObject.lineId;
	                	showDetail();
//	                	exportPdfUrl="";
//	                	exportPdfUrl="/qualityAnlsDetail/exportTBsStatDayBhv";
	                	searchByBhvType("#tBsStatDayBhvGrid",beginTime,endTime,bhvType,lineId);
	                }
	            }},
			{name: "reportDate", label:"日期(周)"},
			{name: "carCount", label:"车台数", align: "right"},
			{name: "occurCount", label:"发生次数", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "dayOnWeak", label:"同比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "todo", label: "图表分析", formatter: 'operArea',align: "center",
				formatoptions: [
					{
						css:'icon-chart',
						click: function (data) {
							getViewChartDialog('bhv',data);
						}
					}]
			}]
	});
	//故障统计
	$('#tBsStatWeakMftGrid').grid({
		url : "/qualityAnlsSummary/searchTBsStatWeakMftPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpId", label:"corpId",hidden: true},
			{name: "organId", label:"organId",hidden: true},
			{name: "lineId", label:"lineId",hidden: true},
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "reportDate", label:"日期(周)"},
			{name: "mftDiscCode",label:"故障区分代码",hidden: true},
			{name: "mftTypeCode",label:"故障类型代码",hidden: true},
			{name: "mftTypeName",label:"故障类型名称",formatter:"customCurrency", 
				formatoptions:{
	                redbtn:true,
	                css:'text-link',
	                clickFn:function(rowObject,cellvalue){
	                	var reportDate = rowObject.reportDate;
	                	var beginTime = reportDate.substring(0,10);
	                	var endTime = reportDate.substring(11,21);
	                	var organId = rowObject.organId;
	                	var mftTypeCode = rowObject.mftTypeCode;
	                	var mftDiscCode = rowObject.mftDiscCode;
	                	showDetail();
	    				$("#tBsStatDayBhvDiv, #tBsStatDayMftDiv, #tBsStatDayOnlineDiv, #tBsStatDayMileDiv, #tBsStatDayEnerConsDiv, #tBsStatDayStopDiv").hide();
	    				$("#tBsStatDayMftDiv").show();
	    				$("#tBsStatDayBhvPage, #tBsStatDayMftPage, #tBsStatDayOnlinePage, #tBsStatDayMilePage, #tBsStatDayEnerConsPage ,#tBsStatDayStopPage").removeClass("active");
	    				$("#tBsStatDayMftPage").addClass("active");
	                	searchByMft("#tBsStatDayMftGrid",beginTime,endTime,organId,mftDiscCode,mftTypeCode);
	                }
	            }},
			{name: "carCount", label:"车台数", align: "right"},
			{name: "occurCount", label:"发生次数", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "dayOnWeak", label:"同比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "todo", label: "图表分析", formatter: 'operArea',align: "right",
				formatoptions: [
					{
						css:'icon-chart',
						click: function (data) {
							getViewChartDialog('mft',data);
						}
					}]
			}]
	});
	//在线率统计
	$('#tBsStatWeakOnlineGrid').grid({
		url : "/qualityAnlsSummary/searchTBsStatWeakOnlinePage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpId", label:"corpId",hidden: true},
			{name: "organId", label:"organId",hidden: true},
			{name: "lineId", label:"lineId",hidden: true},
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "reportDate", label:"日期(周)"},
			{name: "carCount", label:"车台数", align: "right"},
			{name: "onlineRate", label:"在线率%", align: "right"},
			{name: "baseLineValue", label:"基准值%", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "dayOnWeak", label:"同比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "todo", label: "图表分析", formatter: 'operArea',align: "center",
				formatoptions: [
					{
						css:'icon-chart',
						click: function (data) {
							getViewChartDialog('online',data);
						}
					}]
			}]
	});
	//里程统计
	$('#tBsStatWeakMileGrid').grid({
		url : "/qualityAnlsSummary/searchTBsStatWeakMilePage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路",width:70},
			{name: "reportDate", label:"日期(周)",width:170},
			{name: "carCount", label:"车台数", align: "right",width:70},
			{name: "maxRngMile", label:"差值里程", align: "right"},
			{name: "sumRngMile", label:"叠加里程", align: "right"},
			{name: "commMinRngMile", label:"能耗表最小当日累计里程", align: "right",hidden: true},
	        {name: "commMaxRngMile", label:"能耗表最大当日累计里程", align: "right",hidden: true},
			{name: "tyMile", label:"全流量里程值", align: "right"},
			{name: "custMile", label:"客户里程值", align: "right"},
			{name: "lineAvgMile", label:"线路平均里程", align: "right"},
			{name: "mileOffset", label:"里程偏差", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "dayOnWeak", label:"同比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			}]
	});
	//能耗统计
	$('#tBsStatWeakEnerConsGrid').grid({
		url : "/qualityAnlsSummary/searchTBsStatWeakEnerConsPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路",width:70},
			{name: "reportDate", label:"日期(周)",width:170},
			{name: "carCount", label:"车台数", align: "right",width:70},
			{name: "fuelType", label:"能源类型",width:80},
			{name: "maxRngEnerCons", label:"差值能耗", align: "right",width:80},
			{name: "sumRngEnerCons", label:"叠加能耗", align: "right",width:80},
			{name: "commMinRngEnerCons", label:"能耗表最小当日累计能耗", align: "right",hidden: true},
			{name: "commMaxRngEnerCons", label:"能耗表最大当日累计能耗", align: "right",hidden: true},
			{name: "tyEnerCons", label:"全流量能耗值", align: "right",width:110},
			{name: "custEnerCons", label:"客户能耗值", align: "right"},
			{name: "lineAvgEnerCons", label:"线路平均能耗", align: "right"},
			{name: "enerConsOffset", label:"能耗偏差", align: "right"},
			{name: "enerConsPMile", label:"百公里能耗", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
			{name: "dayOnWeak", label:"同比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			}]
	});
	//报站统计
	$('#tBsStatWeakStopGrid').grid({
        url: "/qualityAnlsSummary/searchTBsStatWeakStopPage.htm",
        multiselect: false,
        height: gridHeight1,
        width: gridWidth1,
        colModel: [
            {name: "corpName", label: "公司名称"},
            {name: "corpId", label: "企业ID",hidden: true},
            {name: "organName", label: "车队名称",hidden: true},
            {name: "organId", label: "机构ID",hidden: true},
            {name: "lineId", label: "线路ID",hidden: true},
            {name: "lineName", label: "运营线路"},
            {name: "reportDate", label: "日期(周)", width: 180},
            {name: "ranksNum", label: "趟数", align: "right"},
            {name: "allStnNum", label: "全部站数"},
            {name: "exeStnNum", label: "执行站数", align: "right"},
            {name: "realStnNum", label: "实际站数", align: "right"},
            {name: "nullStnNum", label: "无报站数量", align: "right" ,
                formatter: function (cellvalue, options, rowObject) {
                    if(cellvalue > 0){
                        return '<a class="c-red" >'+cellvalue+'</a>';;
                    }
                    return cellvalue;
                }},
            {name: "ifUpDn", label: "是否包含上下行", align: "right",
                formatter: function (cellvalue, options, rowObject) {
        			 if(cellvalue == '否'){
                        return '<a class="c-red" >'+'否'+'</a>';;
					}
                    return cellvalue;
                }},
            {name: "rpStnRate", label: "报站率", align: "right",
				formatter: function (cellvalue, options, rowObject) {
                return "<a>"+cellvalue+'%'+"</a>";
            }},
            {
                name: "dayOnDay", label: "环比", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                    return getcompare(cellvalue);
                }
            },
            {
                name: "dayOnWeak", label: "同比", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                    return getcompare(cellvalue);
                }
            }]
    });

	//质量分析明细页面
	//质量分析明细
	$("#tBsStatDayBhvPage, #tBsStatDayMftPage, #tBsStatDayOnlinePage, #tBsStatDayMilePage, #tBsStatDayEnerConsPage, #tBsStatDayStopPage").click(function(){
		//改变按钮样式
		$("#tBsStatDayBhvPage, #tBsStatDayMftPage, #tBsStatDayOnlinePage, #tBsStatDayMilePage, #tBsStatDayEnerConsPage, #tBsStatDayStopPage").removeClass("active");
		$(this).addClass("active");
		//切换功能区域显示
		$("#tBsStatDayBhvDiv, #tBsStatDayMftDiv, #tBsStatDayOnlineDiv, #tBsStatDayMileDiv, #tBsStatDayEnerConsDiv, #tBsStatDayStopDiv").hide();
		idStr = $(this).attr("id");
		var page = $(this).attr('id');
		exportPdfUrl="";
		exportPdfUrl='/qualityAnlsDetail/exportT'+page.substring(1).replace("Page","");
		getQualityAnlsDetailPage("#"+idStr.replace("Page","Grid"));
		$("#"+idStr.replace("Page","Div")).show();
	});
	
	//初始化明细表格
	//行为明细
	$('#tBsStatDayBhvGrid').grid({
		url : "/qualityAnlsDetail/searchTBsStatDayBhvPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "reportDate", label:"日期(天)"},
			{name: "bhvType",label:"行为类型"},
			{name: "occurCount", label:"发生次数", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
	        {name: "dayOnWeak", label:"同比", align: "right",
	        	formatter: function (cellvalue, options, rowObject) {
	        		return getcompare(cellvalue);
				}
			}]
		});
	//故障明细
	$('#tBsStatDayMftGrid').grid({
		url : "/qualityAnlsDetail/searchTBsStatDayMftPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "reportDate", label:"日期(天)"},
			{name: "mftDiscCode",label:"故障区分代码",hidden: true},
			{name: "mftTypeCode",label:"故障类型代码",hidden: true},
			{name: "mftTypeName",label:"故障类型名称"},
			{name: "occurCount", label:"发生次数", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
	        {name: "dayOnWeak", label:"同比", align: "right",
	        	formatter: function (cellvalue, options, rowObject) {
	        		return getcompare(cellvalue);
				}
			}]
		});
	//在线率明细
	$('#tBsStatDayOnlineGrid').grid({
		url : "/qualityAnlsDetail/searchTBsStatDayOnlinePage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "reportDate", label:"日期(天)"},
			{name: "onlineRate", label:"在线率%", align: "right"},
			{name: "baseLineValue", label:"基准值%", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getOnline(cellvalue);
				}
			},
	        {name: "dayOnWeak", label:"同比", align: "right",
	        	formatter: function (cellvalue, options, rowObject) {
	        		return getOnline(cellvalue);
				}
			}]
		});
	//里程明细
	$('#tBsStatDayMileGrid').grid({
		url : "/qualityAnlsDetail/searchTBsStatDayMilePage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "reportDate", label:"日期(天)"},
			{name: "maxRngMile", label:"差值里程", align: "right"},
			{name: "sumRngMile", label:"叠加里程", align: "right"},
			{name: "commMinRngMile", label:"能耗表最小当日累计里程",hidden: true,align: "right"},
	        {name: "commMaxRngMile", label:"能耗表最大当日累计里程",hidden: true, align: "right"},
			{name: "tyMile", label:"全流量里程值", align: "right"},
			{name: "custMile", label:"客户里程值", align: "right"},
			{name: "lineAvgMile", label:"线路平均里程", align: "right"},
			{name: "mileOffset", label:"里程偏差", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
	        {name: "dayOnWeak", label:"同比", align: "right",
	        	formatter: function (cellvalue, options, rowObject) {
	        		return getcompare(cellvalue);
				}
			}]
		});
	//能耗明细
	$('#tBsStatDayEnerConsGrid').grid({
		url : "/qualityAnlsDetail/searchTBsStatDayEnerConsPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"公司名称"},
			{name: "lineName", label:"运营线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "reportDate", label:"日期(天)"},
			{name: "fuelType", label:"能源类型"},
			{name: "maxRngEnerCons", label:"差值能耗", align: "right"},
			{name: "sumRngEnerCons", label:"叠加能耗", align: "right"},
			{name: "commMinRngEnerCons", label:"能耗表最小当日累计能耗", hidden: true, align: "right"},
			{name: "commMaxRngEnerCons", label:"能耗表最大当日累计能耗", hidden: true, align: "right"},
			{name: "tyEnerCons", label:"全流量能耗值", align: "right"},
			{name: "custEnerCons", label:"客户能耗值", align: "right"},
			{name: "lineAvgEnerCons", label:"线路平均能耗", align: "right"},
			{name: "enerConsOffset", label:"能耗偏差", align: "right"},
			{name: "enerConsPMile", label:"百公里能耗", align: "right"},
			{name: "dayOnDay", label:"环比", align: "right",
				formatter: function (cellvalue, options, rowObject) {
					return getcompare(cellvalue);
				}
			},
	        {name: "dayOnWeak", label:"同比", align: "right",
	        	formatter: function (cellvalue, options, rowObject) {
	        		return getcompare(cellvalue);
				}
			}]
		});
    //报站明细
    $('#tBsStatDayStopGrid').grid({
        url: "/qualityAnlsDetail/searchTBsStatDayStnPage.htm",
        multiselect: false,
        height: gridHeight1,
        width: gridWidth1,
        colModel: [
            {name: "corpName", label: "公司名称", align: "left"},
            {name: "corpId", label: "企业ID",hidden: true},
            {name: "organName", label: "车队名称",hidden: true},
            {name: "organId", label: "机构ID",hidden: true},
            {name: "lineId", label: "线路ID",hidden: true},
            {name: "carId", label: "车辆ID",hidden: true},
            {name: "lineName", label: "运营线路", align: "left"},
            {name: "reportDate", label: "日期(周)", width: 180, align: "right"},
            {name: "licPltNo", label: "车牌号", align: "left"},
            {name: "eqmtCode", label: "设备编号", align: "right"},
            {name: "ranksNum", label: "趟数", align: "right"},
            {name: "upRanksNum", label: "上行趟数", align: "right"},
            {name: "dnRanksNum", label: "下行趟数", align: "right"},
            {name: "otRanksNum", label: "其他趟数", align: "right"},
            {name: "allStnNum", label: "全部站数", align: "right"},
            {name: "exeStnNum", label: "执行站数", align: "right"},
            {name: "realStnNum", label: "实际站数", align: "right"},
            {name: "nullStnNum", label: "无报站数量", align: "right" ,
                formatter: function (cellvalue, options, rowObject) {
                    if(cellvalue > 0){
                        return '<a class="c-red" >'+cellvalue+'</a>';;
                    }
                    return cellvalue;
                }},
            {name: "ifUpDn", label: "是否包含上下行", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                     if(cellvalue == '否'){
                        return '<a class="c-red" >'+'否'+'</a>';;
                    }
                    return cellvalue;
                }},
            {name: "upStns", label: "上行报站", align: "right",hidden: true},
            {name: "dnStns", label: "下行报站", align: "right",hidden: true},
            {name: "otStns", label: "其他报站", align: "right",hidden: true},
            {name: "upStnLost", label: "上行缺报站", align: "right"},
            {name: "dnStnLost", label: "下行缺报站", align: "right"},
            {name: "otStnLost", label: "其他缺报站", align: "right"},
            {name: "rpStnRate", label: "报站率", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                    return "<a>"+cellvalue+'%'+"</a>";
                }},
            {
                name: "dayOnDay", label: "环比", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                    return getcompare(cellvalue);
                }
            },
            {
                name: "dayOnWeak", label: "同比", align: "right",
                formatter: function (cellvalue, options, rowObject) {
                    return getcompare(cellvalue);
                }
            }]
    });
	
	function getcompare(cellvalue){
		if(cellvalue>0){
			return '<a class="icon-compare-up" >'+cellvalue+'%'+'</a>';
		}else{
			return '<a class="icon-compare-down" >'+cellvalue+'%'+'</a>';
		}
	}
	
	function getOnline(cellvalue){
		if(cellvalue<0){
			return '<a class="icon-compare-up" >'+cellvalue+'%'+'</a>';
		}else{
			return '<a class="icon-compare-down" >'+cellvalue+'%'+'</a>';
		}
	}
	
	function getQualityAnlsDetailPage(obj) {
		var params={};
		params.type="CAR";
		params.carType="2";
		params.orgIds=getCheckedCarNodes();
		params.reportDate = $("#reportDate").val();
		params.dayOnDay = $("#dayOnDay").val();
		params.dayOnWeak = $("#dayOnWeak").val();
		if(getCheckedCarNodes().length > 0){
			objGrid(obj,params);
		}
    }
	
	function searchByBhvType(obj,beginTime,endTime,bhvType,lineId){
		var params={};
		params.carType="1";
		params.beginTime = beginTime;
		params.endTime = endTime;
		params.bhvType = bhvType;
		params.lineId = lineId;
		objGrid(obj,params);
	}
	
	function searchByMft(obj,beginTime,endTime,organId,mftDiscCode,mftTypeCode){
		var params={};
		params.carType="1";
		params.beginTime = beginTime;
		params.endTime = endTime;
		params.mftDiscCode = mftDiscCode;
		params.mftTypeCode = mftTypeCode;
		params.organId = organId;
		objGrid(obj,params);
	}
	
	function objGrid(obj,params){
		$(obj).grid('setGridParam', {
			datatype: "JSON",
			page: 1,
			postData: params
		}).trigger("reloadGrid");
	}

	//车辆问题分析页面
	//分页查询车辆问题分析
	$('#carQuestionAnlsGrid').grid({
		url : "/carQuestionAnls/searchTBsStatProbAnaPage.htm",
		multiselect:false,
		height: gridHeight1,
		width: gridWidth1,
		colModel:[
			{name: "corpName", label:"企业名称"},
			{name: "lineName", label:"营运线路"},
			{name: "licPltNo", label:"车牌号"},
			{name: "todo", label: "详细清单" ,formatter: 'operArea', align: "center",
				formatoptions: [
					{
						text: '详细',
						css:'operate-scan',
						click: function (data) {
//							if(data.errorLevel){
//								errorLevel=data.errorLevel.substr(data.errorLevel.indexOf('>')+1,data.errorLevel.indexOf('</')-data.errorLevel.indexOf('>')-1);
//								data.errorLevel=errorLevel;
//							}
//							getEditDialog1().dialog('exec', 'accept',data.corpName,data.lineName,data.licPltNo,data.reportDate,data.onlineProbAna,data.mileProbAna,data.enerConsProbAna,data.mftProbAna,data.bhvProbAna);
//							console.info(data);
							getEditDialog1().dialog('exec', 'loadData',data);
						}
					}]
			},
			{name: "reportDate", label:"日期（天）"},
			{name: "onlineProbAna", label:"在线率问题"},
			{name: "mileProbAna", label:"里程问题"},
			{name: "enerConsProbAna", label:"能耗问题"},
			{name: "mftProbAna", label:"故障问题"},
			{name: "bhvProbAna", label:"行为问题"},
            {name: "stnProbAna", label:"报站问题",
				formatter: function (cellvalue, options, rowObject) {
                    if(!cellvalue){
                        return '';
                    }
                    if(cellvalue.toString().indexOf("上下行")>0) {
                        var pro = cellvalue.toString().replace(new RegExp("（上下行/站点编号）", 'g'), "");
                        if (pro.indexOf("%0(")>0) {
                            pro = pro.replace("%0","%[上行,站点编号:");
                            pro = pro.replace("),",")],");
                        }
                        if (pro.indexOf("%1(")>0) {
                            pro = pro.replace("%1","%[下行,站点编号:");
                        }
                        if (pro.indexOf("%2(")>0) {
                            pro = pro.replace("%2","%[环行,站点编号:");
                        }
						console.info(pro);
						return pro+"]";
                    }
                return cellvalue;
            }},
			{name: "onlineOptSug", label:"在线率建议", hidden: true},
			{name: "mileOptSug", label:"里程建议", hidden: true},
			{name: "enerOptSug", label:"能耗建议", hidden: true},
			{name: "mftOptSug", label:"故障建议", hidden: true},
			{name: "bhvOptSug", label:"行为建议", hidden: true},
            {name: "stnOptSug", label:"报站建议", hidden: true}
		]
	});
	
	getEditDialog1=function(fn) {
		if (!$editDialog) {
			$editDialog = $('<div>').dialog({
				url: './report/dataQualityIndex/carProblemDetails.htm',
				title:'详细清单',
				height: 630,
				width: 720,
				buttons: [
					{
						text: '关闭',
						css: 'btn-cancel',
						click: function () {
							$(this).dialog('close');
						}
					}
				]
			});
		}
//		$editDialog.dialog('exec', 'loadData',data);
		$editDialog.dialog('open');
		return $editDialog;
	}
	
	
    //加载车辆问题分析
	function loadarQuestionAnlsGrid(){
		var params={};
		params.type="CAR";
		params.orgIds=getCheckedCarNodes();
		params.reportDate = $("#reportDate").val();
		idStr = $(this).attr("id");
		if(getCheckedCarNodes().length > 0){
			exportPdfParams.type="CAR";
			exportPdfParams.orgIds=getCheckedCarNodes();
			exportPdfParams.reportDate = $("#reportDate").val();
			$("#carQuestionAnlsGrid").grid('setGridParam', {
				datatype: "JSON",
				page: 1,
				postData: params
			}).trigger("reloadGrid");
		}
	}
	function showDetail(){
		$("#qualityIndexDiv, #qualityAnlsSummaryDiv, #carQuestionAnlsDiv").hide();
        $(".item6, .item7, .item8, .item9").removeClass("active");
    	$(".item8").addClass("active");
    	$("#qualityAnlsDetailDiv").show();
    	$("#carTreeUl").show();
		$("#lineChkBox").hide();
		$("#corpTreeUl").hide();
		$("#orgSelect").html("车辆选择");
	}
	
	//获取左侧选择的节点信息
    function getPostData() {
        var rcx = getCheckedCarNodes();
        if (rcx) {
            postData = $.extend(rcx, $("#top").parent().getValues());
        }
        if (!postData.beginTime||!postData.endTime) {
        	 $.messager.alert("提示", "请选择查询起止时间段", "info");
        
             return false;
        }
        
//        postData = $.extend(postData, passParams);
       return rcx;
    }
    var  getWidth2 = $("#unBehPct").width();
    $("#statisticalInfoGrid").grid({
		url : "/carQuestionAnls/getCarProblemPage.htm",
		multiselect:false,
		showPager:false,
		height: 233,
		width: ($(window).width()-158-80)/2,
		colModel:[
			{name: "type", label:"类型", align: "center"},
			{name: "proportion", label:"占比", align: "center",
				formatter: function (cellvalue, options, rowObject) {
					return '<a>'+cellvalue+'%'+'</a>';;
				}
			},
			{name: "frequency", label:"次数", align: "center"}
			
		]
	});
    
    
    
	function search() {
		if(getCheckedCarNodes().length < 1){
			 $.messager.alert("提示", "请选择车辆", "info");
			 return false;
		}
    	if (getPostData()) {
//    		console.info(getCheckedCarNodes());
    		var params={};
    		params.beginTime = postData.beginTime;
    		params.endTime = postData.endTime;
    		params.orgIds=getCheckedCarNodes();
    		$('#statisticalInfoGrid').grid('setGridParam', {
                page: 1,
                datatype: "json",
                postData: params
            }).trigger("reloadGrid");
    		//加载grid的同时加载饼图
    		$.ajaxExt({
    			url:"/carQuestionAnls/getCarProblemPage.htm",
    			data:params
    		}).done(function(result){
    			var series = [{
                    type: 'pie',
                    name: '故障统计',
                    data: []
                }];
    			if(result){
                    $.each(result, function (index, item) {
                        series[0].data.push({name: item.type, y: item.proportion});
                    });
    			}
    			loadPieChart('#chart', '', series);
    		});
    		//加载车辆问题分析
    		params.type="CAR";
    		idStr = $(this).attr("id");
//    		console.info(postData.problemType);
    		params.problemType = postData.problemType;
    		if(getCheckedCarNodes().length > 0){
    			exportPdfParams.type="CAR";
    			exportPdfParams.orgIds=getCheckedCarNodes();
    			exportPdfParams.reportDate = $("#reportDate").val();
    			$("#carQuestionAnlsGrid").grid('setGridParam', {
    				datatype: "JSON",
    				page: 1,
    				postData: params
    			}).trigger("reloadGrid");
    		}
    	}   
	}
	
	$topBar.on('click', '[name=problemType] a', function () {
		search();
	});
	
	//饼图
    function loadPieChart(divId, text, series) {
        $(divId).parent().show();
        $(divId).highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: text
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        format: '<b>{point.name}</b>: {y} %'
                    },
                    showInLegend: true
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                labelFormatter: function () {
                    return this.name;
                },
                floating: false
            },
            series: series,
            credits: {
                enabled: false
            }
        });
    }
    
});